/**
 * 
 */
package com.net.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.servlet.ServletUtilities;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.net.service.chart.ColumnaServicerImp;
import com.net.service.chart.ColumnarService;
import com.net.service.chart.FoldLineService;
import com.net.service.chart.FoldLineServiceImpl;
import com.net.service.chart.PieService;
import com.net.service.chart.PieServiceImpl;

/**
 *
 * @author fengcheng
 * @date 2018年6月25日 下午12:57:12
 */
@Controller
public class ChartApi {
	@RequestMapping(value = "getColumnChart.do")
	public ModelAndView getColumnChart(HttpServletRequest request,
	        HttpServletResponse response, ModelMap modelMap) throws Exception {
	   ColumnarService columnarService= new ColumnaServicerImp();
		// 在业务层获取创建的柱状图（此时柱状图已经创建完成的）
	    JFreeChart chart = columnarService.createColumnarTools();
	    // 将图形转换为图片传到dateSet.jsp
	    String fileName = ServletUtilities.saveChartAsJPEG(chart, 700, 400,
	            null, request.getSession());
	    String chartURL = request.getContextPath() + "/chart?filename="
	            + fileName;
	    modelMap.put("chartColumnURL", chartURL);
	    return new ModelAndView("dateSet", modelMap);
	}
	@RequestMapping(value = "getPieChart.do")
	public ModelAndView getPieChart(HttpServletRequest request,
	        HttpServletResponse response, ModelMap modelMap) throws Exception {
	   PieService pieService= new PieServiceImpl();
	   String ip = request.getParameter("ip");
		// 在业务层获取创建的柱状图（此时柱状图已经创建完成的）
	    JFreeChart chart = pieService.createPieTools(ip);
	    // 将图形转换为图片传到dateSet.jsp
	    String fileName = ServletUtilities.saveChartAsJPEG(chart, 700, 400,
	            null, request.getSession());
	    String chartURL = request.getContextPath() + "/chart?filename="
	            + fileName;
	    modelMap.put("chartPieURL", chartURL);
	    return new ModelAndView("pie", modelMap);
	}
	@RequestMapping(value = "getLineChart.do")
	public ModelAndView getLineChart(HttpServletRequest request,
	        HttpServletResponse response, ModelMap modelMap) throws Exception {
	    FoldLineService foldLineService= new FoldLineServiceImpl();
		// 在业务层获取创建的柱状图（此时柱状图已经创建完成的）
	    JFreeChart chart = foldLineService.createFoldLineTools();
	    // 将图形转换为图片传到dateSet.jsp
	    String fileName = ServletUtilities.saveChartAsJPEG(chart, 700, 400,
	            null, request.getSession());
	    String chartURL = request.getContextPath() + "/chart?filename="
	            + fileName;
	    modelMap.put("chartLineURL", chartURL);
	    return new ModelAndView("dateSet", modelMap);
	}
}
